package controlSoftware;

import java.awt.Canvas;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

import controlSoftware.DataIn.DataIn;
import controlSoftware.DataIn.TelnetParser;
import controlSoftware.userThread.Device;
import controlSoftware.userThread.SensorData;
import controlSoftware.userThread.UserThread;

public class mainUI {

	public JFrame frame;
	public JTextField textField;
	public static Canvas canvas1;
	public static Device [] ActiveObjs = new Device [2];
	
	Device testObj = new Device (1, "Starfy", "Chang");
	
	/**
	 * Launch the application.
	 */
	public static void main(String args[]) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					mainUI window = new mainUI();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
		
	}

	/**
	 * Create the application.
	 */
	public mainUI() {
		initialize();
		
		Queue<SensorData> user1Data = new ConcurrentLinkedQueue<SensorData>();
		
		DataIn dataIn = new DataIn("User 1 DataIn", user1Data, "192.168.1.136", 80);
		UserThread thread1 = new UserThread("User 1 DataProcessing", user1Data);
		new Thread(thread1).start();
		new Thread(dataIn).start();
	}
	

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frame = new JFrame();
		frame.setBounds(0, 0, 800, 600);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setResizable(false);
		frame.getContentPane().setLayout(null);

		canvas1 = new Canvas();
		canvas1.setBounds(10, 10, 777, 510);
		canvas1.setBackground(Color.WHITE);
		frame.getContentPane().add(canvas1);
		
		JButton btnStart = new JButton("Start");
		btnStart.setBounds(85, 538, 94, 23);
		frame.getContentPane().add(btnStart);
		
		JButton btnReset = new JButton("Reset");
		btnReset.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				
			}
		});
		btnReset.setBounds(189, 538, 89, 23);
		frame.getContentPane().add(btnReset);
		
		JLabel lblPanel = new JLabel(testObj.getFirstName() + " " + testObj.getLastName());
		lblPanel.setBounds(316, 538, 120, 23);
		frame.getContentPane().add(lblPanel);
		frame.setVisible(true);
	}
}
